home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / netlib / init_inet_daemon.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  2KB  |  83 lines

  1. RCS_ID_C="$Id: init_inet_daemon.c,v 4.2 1994/09/30 00:35:04 jraja Exp $";
  2. /*
  3.  *      init_inet_daemon.c - obtain socket accepted by the inetd
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. /****** net.lib/init_inet_daemon ****************************************
  11.  
  12.     NAME
  13.         init_inet_daemon - obtain socket accepted by the inetd
  14.  
  15.     SYNOPSIS
  16.         int init_inet_daemon(void);
  17.  
  18.     FUNCTION
  19.         Obtain the server socket accepted by the inetd, the Internet
  20.         super-server.
  21.  
  22.     RETURN VALUES
  23.         socket descriptor if successful, -1 with specific error code
  24.         on errno otherwise.
  25.  
  26.     ERRORS
  27.         ENXIO     - The process was not started by the inetd.
  28.  
  29.     NOTES
  30.         If the process was started by the inetd, but the ObtainSocket()
  31.         call fails, then this function exit()s with some specific exit
  32.         code, so that inetd can clean up the unobtained socket.
  33.  
  34.         Use the net.lib function set_socket_stdio() to redirect stdio,
  35.         stdout and stderr to the returned socket, if necessary.
  36.  
  37.     SEE ALSO
  38.         serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
  39.         netutil/inetd
  40. *****************************************************************************
  41. *
  42. */
  43.  
  44. #include <exec/types.h>
  45. #include <dos/dosextens.h>
  46.  
  47. #include <proto/socket.h>
  48. #include <proto/exec.h>
  49.  
  50. #include <stdlib.h>
  51. #include <errno.h>
  52. #include <inetd.h>
  53.  
  54. int
  55. init_inet_daemon(void)
  56. {
  57.   struct Process *me = (struct Process *)FindTask(NULL);
  58.   struct DaemonMessage *dm = (struct DaemonMessage *)me->pr_ExitData;
  59.   int sock;
  60.  
  61.   if (dm == NULL) {
  62.     /*
  63.      * No DaemonMessage, return error code
  64.      */    
  65.     errno = ENXIO; /* "Device not configured" */
  66.     return -1;
  67.   }
  68.   
  69.   /*
  70.    * Obtain the server socket
  71.    */
  72.   sock = ObtainSocket(dm->dm_Id, dm->dm_Family, dm->dm_Type, 0);
  73.   if (sock < 0) {
  74.     /*
  75.      * If ObtainSocket fails we need to exit with this specific exit code
  76.      * so that the inetd knows to clean things up
  77.      */
  78.     exit(DERR_OBTAIN);
  79.   }
  80.  
  81.   return sock;
  82. }
  83.